package lq8095;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
class HuffmanNode {
	char c; //字符
	int f;  //出现次数
	HuffmanNode l, r; //左右子节点
	public HuffmanNode(char c, int f) {
		this.c = c;
		this.f = f;
		this.l = null;
		this.r = null;
	}
	public HuffmanNode(char c, int f, HuffmanNode l, HuffmanNode r) {
		this.c = c;
		this.f = f;
		this.l = l;
		this.r = r;
	}
	public boolean isLeaf() {
		return l == null && r == null;
	}
}
public class Main {
	// 字符出现频率
	public static Map<Character, Integer> freq = new HashMap<>();
	// 字符对应huffman编码长度
	public static Map<Character, Integer> hcl = new HashMap<>();
	// huffman树的根
	public static HuffmanNode root = null;
	// 构建Huffman树
	static HuffmanNode buildHuffmanTree(String text) {
		// 1. 统计字符频率
		for (char c : text.toCharArray()) {
			freq.put(c, freq.getOrDefault(c, 0) + 1);
		}
		// 2. 创建优先队列（最小堆）
		PriorityQueue<HuffmanNode> pq = new PriorityQueue<HuffmanNode>(new Comparator<HuffmanNode>() {
			@Override
			public int compare(HuffmanNode o1, HuffmanNode o2) {
				return o1.f - o2.f;
			}
		});
		// 遍历 map
		for (Map.Entry<Character, Integer> entry : freq.entrySet()) {
			pq.add(new HuffmanNode(entry.getKey(), entry.getValue()));
		}
		// 3. 构建Huffman树
		while (pq.size() > 1) {
			HuffmanNode left = pq.poll();
			HuffmanNode right = pq.poll();
			// 非叶子节点用原字符串不包含的'\0'表示
			HuffmanNode parent = new HuffmanNode('\0', left.f + right.f, left, right);
			pq.add(parent);
		}
		return pq.poll();
	}

	// 生成Huffman编码表
	// 遍历 root 到每个叶子的路径
	static void generateCodes(HuffmanNode node, int l) {
		if (node == null)
			return;
		if (node.isLeaf()) {
			hcl.put(node.c, l);
			return;
		}
		generateCodes(node.l, l + 1);
		generateCodes(node.r, l + 1);
	}

	// 编码文本长度
	static int encode(String text) {
		if (text == null || text.isEmpty())
			return 0;
		// 构建Huffman树
		root = buildHuffmanTree(text);
		// 生成编码表
		generateCodes(root, 0);
		// 输出码表
//		for (Map.Entry<Character, Integer> entry : hcl.entrySet()) {
//			System.out.printf("%s,%d\n", entry.getKey(), entry.getValue());
//		}
		// 计算编码文本长度
		int res = 0;
		for (char c : text.toCharArray()) {
			res += hcl.get(c);
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		// 输入优化
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		// 输出ASCII编码长度
		System.out.println(str.length()*8);
		// 输出Huffman编码长度
		System.out.println(encode(str));
	}
}
